package com.atguigu.gmall.payment.config;

import com.atguigu.gmall.rabbit.constant.RabbitConst;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class PaymentRabbitMqConfig {

    //创建队列
    @Bean(RabbitConst.QUEUE_PAYMENT_PAY)
    public Queue createQueue(){
        return QueueBuilder.durable(RabbitConst.QUEUE_PAYMENT_PAY).build();
    }

    //创建交换机
    @Bean(RabbitConst.EXCHANGE_DIRECT_PAYMENT_PAY)
    public Exchange createExchange(){
        return ExchangeBuilder.directExchange(RabbitConst.EXCHANGE_DIRECT_PAYMENT_PAY).build();
    }

    //创建绑定
    public Binding createBinding(@Qualifier(RabbitConst.QUEUE_PAYMENT_PAY) Queue queue,
                                 @Qualifier(RabbitConst.EXCHANGE_DIRECT_PAYMENT_PAY) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(RabbitConst.ROUTING_PAYMENT_PAY).noargs();
    }

}
